package com.yonyougov.devops.cruxcisupport.role;

import com.yonyougov.devops.cruxcisupport.role.vo.LinkedRoleRespVo;
import com.yonyougov.devops.cruxcisupport.role.vo.NoLinkRoleVo;
import com.yonyougov.devops.cruxcisupport.role.vo.NotLinkedRoleByUserIdDto;
import com.yonyougov.devops.fwc.core.dao.impl.BaseDaoImpl;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Repository;

import java.math.BigInteger;
import java.util.List;

/**
 * t_role数据层实现
 */
@Repository
public class RoleDaoImpl extends BaseDaoImpl<RoleEntity, BigInteger> implements RoleDao {
    private final SqlSessionTemplate sqlSessionTemplate;

    public RoleDaoImpl(SqlSessionTemplate sqlSessionTemplate) {
        this.sqlSessionTemplate = sqlSessionTemplate;
    }

    //<!--用户自定义代码开始-->
    @Override
    public List<RoleEntity> getCurrentUserRoles(BigInteger userId) {
        String statement = RoleEntity.class.getName() + "Mapper.getCurrentUserRoles";
        return sqlSessionTemplate.selectList(statement, userId);
    }

    @Override
    public List<BigInteger> getCurrentUserRoleIds(BigInteger userId) {
        String statement = RoleEntity.class.getName() + "Mapper.getCurrentUserRoleIds";
        return sqlSessionTemplate.selectList(statement, userId);
    }

    @Override
    public int findNoLinkRoleByUserIdCount(NotLinkedRoleByUserIdDto pageParams) {
        String statement = RoleEntity.class.getName() + "Mapper.findNoLinkRoleByUserIdCount";
        return sqlSessionTemplate.selectOne(statement, pageParams);
    }

    @Override
    public List<NoLinkRoleVo> findNoLinkRoleByUserId(NotLinkedRoleByUserIdDto pageParams) {
        String statement = RoleEntity.class.getName() + "Mapper.findNoLinkRoleByUserId";
        return sqlSessionTemplate.selectList(statement, pageParams);
    }

    @Override
    public List<LinkedRoleRespVo> findLinkedRoleByUserId(BigInteger userId) {
        String statement = RoleEntity.class.getName() + "Mapper.findLinkedRoleByUserId";
        return sqlSessionTemplate.selectList(statement, userId);
    }

    //<!--用户自定义代码结束-->
}
